package com.robot.mannge.common.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.aop.interceptor.PerformanceMonitorInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * Mybaits-plus 的一些配置
 * @author mwan
 *
 */
@Configuration
@EnableTransactionManagement
@MapperScan({"com.robot.mannge.*.mapper"})
public class DefaultMybatisPlusConfig {
	
	/**
	 * 分页插件
	 * @return
	 */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);

        interceptor.addInnerInterceptor(paginationInnerInterceptor);
        paginationInnerInterceptor.setOverflow(true);

        return interceptor;
    }

    /**
     * 打印 sql，性能分析拦截器，不建议生产使用
     * 设置 local dev test 环境开启
     */
    @Bean
    @Profile({"local", "dev", "test"})
    public PerformanceMonitorInterceptor performanceMonitorInterceptor() {
        return new PerformanceMonitorInterceptor();
    }

}